<?php
/**
 * 前台公共ajax类
 * @package  ajax
 * @subpackage  shop
 * @author   create by allen.qiang
 */

class ajax_getPwd {

    public function execute() {

        if (isset($_REQUEST['operFlg']) && is_numeric($_REQUEST['operFlg'])) {

            switch($_REQUEST['operFlg']) {

                case 1: //找回密码
                    $this->getPwd();
                    break;

                default:
                    $this->toReturn( '参数错误' );
                    break;

            }

        } else {
            $this->toReturn( '参数错误' );
        }

    }
    
    /**
     * 找回密码
     * @author yinfulin 2013-11-01
     */
    private function getPwd() {

        global $G_SHOP;

        //检查短信验证码
        $sms_ysm = $G_SHOP->sessionCache_get('dxyzm_' . $_REQUEST['mobile']);
        if (is_null($sms_ysm)) {
            $this->toReturn('短信验证码已失效', 400, 'smsyzm');
        } elseif ($sms_ysm != md5($_REQUEST['smsyzm'])) {
            $this->toReturn('短信验证码有误', 400, 'smsyzm');
        }
        $G_SHOP->sessionCache_remove( 'dxyzm_' . $_REQUEST['mobile'] );
        $G_SHOP->sessionCache_remove( 'dxyzm_time_' . $_REQUEST['mobile'] );


        
        //实例化会员类
        $customerHandler = new customerHandler( $G_SHOP->DBCA );
        
//        $_REQUEST['editor'] = $_REQUEST['mobile'];
//        $_REQUEST['eai'] = $G_SHOP->EAI;
//        $_REQUEST['newPwd'] = $_REQUEST['new_pwd'];
        $reset_params = array(
        	'mobile'	=> $_REQUEST['mobile'],
        	'editor'	=> $_REQUEST['mobile'],
        	'eai'		=> $G_SHOP->EAI,
        	'newPwd'	=> $_REQUEST['new_pwd'],
        	'reNewPwd'	=> $_REQUEST['new_pwd_2']
        );

        //重置会员密码
        $result_array = $customerHandler->resetCustPwd($reset_params);

        if ($result_array['code'] != 200) {

            $this->toReturn($result_array['message'], $result_array['code']);

        }
        

        echo json_encode($result_array);

    }

    /**
     * ajax返回信息
     * @param string $msg 信息
     * @param int $code 代码
     * @param mixed $data 返回的数据
     */
    private function toReturn( $msg, $code = 400, $data='' ) {

        die( json_encode( array( 'code' => $code, 'message' => $msg, 'data' => $data ) ) );

    }

}